import string
import sys


from module_info import *
from module_triggers import *
from module_dialogs import *
from module_simple_triggers import *
from module_presentations import *

from process_common import *
from process_operations import *

from patch_scripts import *


#-----------------------------------------------

def compile_patch_global_vars(variable_list, variable_uses, updated_scripts, added_scripts):
    temp_list = []
    list_type = type(temp_list)    
    print "#Scripts begin"
    for i_script in updated_scripts+added_scripts:
      try:
        func = scripts[i_script]
        if (type(func[1]) == list_type):
          compile_global_vars(func[1], variable_list,variable_uses)
        else:
          compile_global_vars(func[2], variable_list,variable_uses)
      except:
        print "Error in script:"
        #print func
        print sys.exc_info()
    print "#Scripts end"
    

print "Updating global_variables..." 
variable_uses = []
variables = load_variables(patch_dir, variable_uses)
for i in range(0, len(variable_uses)):
    variable_uses[i] = 0
compile_patch_global_vars(variables, variable_uses, updated_scripts, added_scripts)
save_variables(patch_dir, variables, variable_uses)